Skip to content

Support nullable optionals and generic collections#921

Merged
snazy merged 2 commits into
projectnessie:mainfrom
snazy:null-opt-gen-coll
Jul 20, 2026
Merged

Support nullable optionals and generic collections#921
snazy merged 2 commits into
projectnessie:mainfrom
snazy:null-opt-gen-coll

Conversation

@snazy

@snazy snazy commented Jul 17, 2026

Copy link
Copy Markdown
Member

Jackson property type inference only recognized List as a CEL list-like type and treated Optional as an object-like value. Runtime adaptation had the same List-only limitation and returned Optional values as ordinary objects.

Generalize runtime list adaptation to Collection, unwrap Optional values to either their contained CEL value or null, and teach the Jackson 2 and Jackson 3 type descriptors to infer Collection as list and Optional as T. Add regression coverage for Collection, Set, Optional.of, Optional.empty, and nested Optional values.

@snazy
snazy requested a review from XN137 July 17, 2026 10:14
XN137
XN137 previously approved these changes Jul 20, 2026
private JavaType elementType(JavaType type) {
JavaType elementType = type.getContentType();
if (elementType == null && type.containedTypeCount() > 0) {
elementType = type.containedType(0);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just to confirm: even for Maps containedType(0) refers to the value type?
or do Maps always have a non-null getContentType ?
do we support raw maps without type parameters?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch! containedType(0) would indeed be the key type for Map<K,V>.
Jackson map types always have a non-null getContentType() representing the value type, including raw maps, for which Jackson uses Object for both key and value.
So the fallback is not reached here and raw maps behave as before.
Still, using elementType() for maps is misleading, so I’ll switch that line back to type.getContentType().

snazy added 2 commits July 20, 2026 12:04
Jackson property type inference only recognized List as a CEL list-like type and treated Optional as an object-like value. Runtime adaptation had the same List-only limitation and returned Optional values as ordinary objects.

Generalize runtime list adaptation to Collection, unwrap Optional values to either their contained CEL value or null, and teach the Jackson 2 and Jackson 3 type descriptors to infer Collection<T> as list<T> and Optional<T> as T. Add regression coverage for Collection, Set, Optional.of, Optional.empty, and nested Optional values.
@snazy
snazy force-pushed the null-opt-gen-coll branch from 2a04fcc to ed87215 Compare July 20, 2026 10:05
@snazy
snazy requested a review from XN137 July 20, 2026 10:05
@snazy
snazy merged commit b45fe3f into projectnessie:main Jul 20, 2026
3 checks passed
@snazy
snazy deleted the null-opt-gen-coll branch July 20, 2026 11:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants